function main_TLS_LRD(I, data_filepath, filename, algorithmsName, iters)
    iFrames = length(I);
    [M, N] = size(I{1,1});
    I_ = zeros(M, N, iFrames);
    for f = 1:iFrames
        I_(:,:,f) = I{f,1};
    end
    
    clip = 1:1:iFrames;
    I_ = I_(:,:,clip);
    [M,N,kI] = size(I_);
    % 使用AIA 计算包裹相位与未知相移量
    % 关于方向的定义  条纹向左  物体向右    设左为正方向
    
    block_size_row = 6; 
    block_size_col = 6;
    block_row_num = M/block_size_row;
    block_col_num = N/block_size_col;
    block_row_num = floor(block_row_num);
    block_col_num = floor(block_col_num);
    phi=zeros(M,N);Amp=zeros(M,N);B=zeros(M,N);
    
    tic
    r=1;
    Delta = cell(iFrames,1);        %预设Delta大小
    Q = 2;                          %勒让德多项式阶次
    Alpha = cell(iFrames,1);        %预设勒让德多项式系数
    for f = 1:iFrames               %初始化Delta和Alpha
        Delta{f,1} = zeros(size(I{f,1})) + mod((f-1),4)*pi/2;
        Alpha{f,1} = zeros(1,(Q+1)*(Q+2)/2);
        Alpha{f,1}(1) = mod((f-1),4)*pi/2;
    end
    
    %提前生成LRD平面矩阵
    [Lrd_Matrix, ~] = create_lrd(M,N,Q);
    
    Delta1 = zeros(M,N,kI);
    for f=1:kI
        Delta1(:,:,f) = Delta{f,1};
    end
    for n = 1:iters
        for i=1:block_row_num
            for j=1:block_col_num
                if i==block_row_num 
                    Mr = M;
                else
                    Mr = (i)*block_size_row;
                end
                if j==block_col_num 
                    Nc = N;
                else 
                    Nc = (j)*block_size_col;
                end
                Ib = I_((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc,:);
    
                ind = find(~isnan(Ib(:,:,1))); %记录非nan的坐标
                [y,A] = constructEqu(Ib,Delta1((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc,:));  %传入子矩阵
    
                [mb,nb,~] = size(Ib);
                if isempty(y) 
                    phi((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc) = nan;
                    Amp((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc) = nan;
                    B((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc) = nan;
                    continue;
                end
    
                X = tls(A,y);          
                
                Ta = ones(size(Ib(:,:,1)))*nan;
                Tb = ones(size(Ib(:,:,1)))*nan;
                Tc = ones(size(Ib(:,:,1)))*nan;
                [x,y] = ind2sub(size(Ib(:,:,1)), ind);
    
                X1 = reshape(X,3,[]);            
                a = X1(1,:);
                Ta(sub2ind(size(Ta),x,y)) = a;
                b = X1(2,:);
                Tb(sub2ind(size(Tb),x,y)) = b;
                c = X1(3,:);
                Tc(sub2ind(size(Tc),x,y)) = c;
                Ta = reshape(Ta,mb,nb);
                phib = atan2(-Tc,Tb);
                phib=reshape(phib,mb,nb);
                Bb = sqrt(Tb.^2+Tc.^2);Bb=reshape(Bb,mb,nb);
                phi((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc) = phib;
                Amp((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc) = Ta;
                B((i-1)*block_size_row+1:Mr,(j-1)*block_size_col+1:Nc) = Bb;
                r=r+1;
            end
        end
        I2 = reshape(I_,M*N,kI);
        if mean(Delta1(:,:,2)) > 1
            phi=-phi;
        end
    
        [Alpha, Delta] = OptimizingGroupS_LRD(Amp,B,phi,Delta,Q,I,Alpha,Lrd_Matrix);
    
        for f=1:kI
            Delta1(:,:,f) = Delta{f,1};
        end
%         epslion = (Amp + B.*cos(phi+Delta{2,1}) - I{2,1}).^2;mesh(epslion);
%         RMSE_epslion = sqrt(sum(epslion(:))/(M*N));
        
        fprintf('----------第%d次迭代-------------\n', n);
    end
    toc
    saveFile2(I, Amp, B, phi, Delta, data_filepath, filename, algorithmsName)
end


